package com.lagou.controller;

import com.lagou.Service.DepartmentService;
import com.lagou.domain.Department;
import com.lagou.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/dep")
public class DepartmentController {
    @Autowired
    DepartmentService departmentService;


    @RequestMapping("/find")
    public String findDep(){
        departmentService.findDepartment();
        return "index";
    }

    @RequestMapping("/insert")
    public String insetDep(){
        Department department = new Department();
        department.setDept_name("1");
        department.setEmail("111");
        department.setTelephone("23123");
        department.setMajor_name("234234");
        departmentService.insertDepartment(department);
        System.out.println("成功！");
        return "index";
    }
    @RequestMapping("/ajax")
    @ResponseBody
    public List<Department> insertDep(@RequestBody Department department){

        System.out.println(department);


        departmentService.insertDepartment(department);
        List<Department> departmentList = departmentService.findDepartment();
        return  departmentList;

    }
    @RequestMapping("/ajaxRequest")
    @ResponseBody
    public User ajaxRequest(@RequestBody User user){
        System.out.println(user);
        return user;
    }
}
